//
//  AppUpdateController.m
//  SmartVideo
//
//  Created by nsm on 2019/3/26.
//  Copyright © 2019 nani. All rights reserved.
//

#import "AppUpdateController.h"

@interface AppUpdateController ()

@end

@implementation AppUpdateController

#pragma mark - lifeCycle

#pragma mark - override

#pragma mark - initialization
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = WhiteColor(0.5, 0.3);
}

- (void)initSubviews {
    [super initSubviews];
    
    MyLinearLayout *layout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
    layout.backgroundColor = COLOR_4;
    layout.size = CGSizeMake(kScreenWidth*0.65, kScreenWidth*0.65*1.4);
    layout.wrapContentHeight = NO;
    layout.myCenter = CGPointZero;
    layout.padding = UIEdgeInsetsMake(15, 15, 15, 15);
    layout.subviewVSpace = 12;
    [self.view addSubview:layout];
    ViewCorner(layout, 9);
    
    UILabel *title = UILabel.new;
    title.myHorzMargin = 0;
    title.wrapContentHeight = YES;
    title.font = [UIFont boldSystemFontOfSize:18];
    title.text = @"发现新版本";
    title.textColor = UIColor.blackColor;
    title.textAlignment = NSTextAlignmentCenter;
    [layout addSubview:title];

    UIScrollView *scrollView = [UIScrollView new];
    scrollView.myHorzMargin = 0;
    scrollView.weight = 1;
    scrollView.showsVerticalScrollIndicator = NO;
    [layout addSubview:scrollView];
    
    MyLinearLayout *contentLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
    contentLayout.myHorzMargin = 0;
    [scrollView addSubview:contentLayout];
    
    UILabel *content = UILabel.new;
    content.myHorzMargin = 0;
    content.wrapContentHeight = YES;
    content.numberOfLines = 0;
    content.font = CustomFont(15);
    content.textColor = COLOR_0;
    [contentLayout addSubview:content];
    content.text = SafeString(self.versionData[@"content"]);
    
    MyLinearLayout *btnLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
    btnLayout.myHorzMargin = 0;
    btnLayout.wrapContentHeight = YES;
    btnLayout.subviewHSpace = 15;
    [layout addSubview:btnLayout];
    
    BOOL forceUpdate = [self.versionData[@"isforce"] isEqual:@"1"];
    if (!forceUpdate) {
        NSMButton *btn = NSMButton.new;
        btn.weight = 1;
        btn.myHeight = 40;
        btn.backgroundColor = GROUP_TABLECOLOR;
        btn.titleLabel.font = CustomFont(15);
        [btn setTitleColor:SUB_TEXT_COLOR forState:UIControlStateNormal];
        btn.title = InternationalString(@"暂不更新");
        [btnLayout addSubview:btn];
        ViewCorner(btn, 6);
        [btn addTarget:self action:@selector(onBtnClickCancel:) forControlEvents:UIControlEventTouchUpInside];
    }
    {
        NSMButton *btn = NSMButton.new;
        btn.weight = 1;
        btn.myHeight = 40;
        btn.backgroundColor = THEME_BTN_BG_COLOR;
        btn.titleLabel.font = CustomFont(15);
        [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        btn.title = InternationalString(@"立即更新");
        [btnLayout addSubview:btn];
        ViewCorner(btn, 6);
        [btn addTarget:self action:@selector(onBtnClickDone:) forControlEvents:UIControlEventTouchUpInside];
    }
}

#pragma mark - setter/getter

#pragma mark - network

#pragma mark - method/public

#pragma mark - method/private

#pragma mark - action
- (void)onBtnClickCancel:(id)sender {
    @nsm_weak(self)
    [self dismissViewControllerAnimated:NO completion:^{
        @nsm_strong(self)
        !self.onClickCancel?:self.onClickCancel();
    }];
}

- (void)onBtnClickDone:(id)sender {
    !self.onClickDone?:self.onClickDone();
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
